package week2;

public class Ex17 {
    public static void main(String[] args) {
        int[] alphaNum = new int[1001];
        alphaNum[1] = 3;alphaNum[2] = 3;alphaNum[3] = 5;alphaNum[4] = 4;alphaNum[5] = 4;
        alphaNum[6] = 3;alphaNum[7] = 5;alphaNum[8] = 5;alphaNum[9] = 4;alphaNum[10] = 3;
        alphaNum[11] = 6;alphaNum[12] = 6;alphaNum[13] = 8;alphaNum[14] = 8;alphaNum[15] = 7;
        alphaNum[16] = 7;alphaNum[17] = 9;alphaNum[18] = 8;alphaNum[19] = 8;alphaNum[20] = 6;
        alphaNum[30] = 6;alphaNum[40] = 5;alphaNum[50] = 5;alphaNum[60] = 5;alphaNum[70] = 7;
        alphaNum[80] = 6;alphaNum[90] = 6;alphaNum[1000] = 11;
        for (int i = 21; i <= 999; ++i){
            if (alphaNum[i] > 0) continue;
            int n,m;
            if (i < 100){
                n = i % 10;
                m = i / 10 % 10;
                alphaNum[i] = alphaNum[m*10] + alphaNum[n];
            }else {
                n = i % 10;
                m = i / 10 % 10;
                n = m * 10 + n;
                m = i / 100 % 10;
                if (n == 0)
                    alphaNum[i] = alphaNum[m] + 7;//'hundred':7
                else
                    alphaNum[i] = alphaNum[n] + alphaNum[m] + 7 + 3;//'hundred':7 'and':3

            }
        }
        int sum = 0;
        for (int s : alphaNum){
            sum += s;
        }
        System.out.println(sum);
    }
}
